package com.ivncorp.evnproject;

import java.util.ArrayList;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

import com.ivncorp.evnproject.adapter.DashboardAdapter;
import com.ivncorp.evnproject.model.ItemDashBoard;

public class FragmentDashboard extends Fragment {
	GridView gridView;
	ArrayList<ItemDashBoard> gridArray = new ArrayList<ItemDashBoard>();
	DashboardAdapter customGridAdapter;

	@Override
	public View onCreateView(LayoutInflater inflater,
			@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.fragment_dashboard, container,
				false);

		// set grid view item
		Bitmap homeIcon = BitmapFactory.decodeResource(this.getResources(),
				R.drawable.box_item_contact);
		Bitmap userIcon = BitmapFactory.decodeResource(this.getResources(),
				R.drawable.box_item_contact);

		gridArray.add(new ItemDashBoard(homeIcon, "Trạm"));
		gridArray.add(new ItemDashBoard(userIcon, "Cột"));
		gridArray.add(new ItemDashBoard(homeIcon, "Tủ TT"));

		gridView = (GridView) view.findViewById(R.id.gridView1);
		customGridAdapter = new DashboardAdapter(getActivity(),
				R.layout.item_grid_dashboard, gridArray);
		gridView.setAdapter(customGridAdapter);
		gridView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				openActivity(position);
			}

		});
		return view;
	}

	void openActivity(int position) {
		Intent intent = null;
		switch (position) {
		case 0:
			intent = new Intent(getActivity(), ActivityGalleryTram.class);
			break;
		case 1:
			intent = new Intent(getActivity(), ActivityGalleryCot.class);
			break;
		case 2:
			intent = new Intent(getActivity(), ActivityGalleryTuTT.class);
			break;

		default:
			intent = new Intent(getActivity(), ActivityGalleryTram.class);
			break;
		}
		
		startActivity(intent);
	}

}
